package cn.itsource.controller.app;

import cn.itsource.pojo.ro.CreateOrderRo;
import cn.itsource.result.JSONResult;
import cn.itsource.service.IOrderService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Tag(name = "小程序订单模块")
@RestController
@RequestMapping("/app/order")
public class AppOrderController {
    @Autowired
    private IOrderService orderService;
    @GetMapping("/inProcess")
    public JSONResult inProcess(){
        return JSONResult.success(orderService.inProcess());
    }

    @PostMapping("/create")
    @Parameter(name ="createOrderRo",description = "创建订单参数")
    public JSONResult create(@RequestBody @Valid CreateOrderRo createOrderRo){
        return JSONResult.success(orderService.create(createOrderRo));
    }


    //自动取消订单
    @PostMapping("/cancel/auto/{orderNo}")
    public JSONResult cancelAuto(@PathVariable("orderNo") String orderNo){
        return JSONResult.success(orderService.cancelAuto(orderNo));
    }

    //手动取消订单
    @PostMapping("/cancel/hand/{orderNo}")
    public JSONResult cancelHand(@PathVariable("orderNo") String orderNo){
        return JSONResult.success(orderService.cancelHand(orderNo));
    }

    @PostMapping("/grabOrders/{orderNo}")
    public JSONResult grabOrders(@PathVariable("orderNo")String orderNo){
        return JSONResult.success(orderService.grabOrders(orderNo));
    }
}
